package com.example.proxydemo;

import android.content.Context;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * @ProjectName: ProxyDemo
 * @Package: com.example.proxydemo
 * @ClassName: GrayFrameLayout
 * @Description: java类作用描述
 * @Author: 作者名
 * @CreateDate: 2021/8/25 10:59
 * @UpdateUser: 更新者：
 * @UpdateDate: 2021/8/25 10:59
 * @UpdateRemark: 更新说明：
 * @Version: 1.0
 */

public class FlipFrameLayout extends FrameLayout {
    private Camera mCamera;
    public FlipFrameLayout(@NonNull Context context) {
        this(context,null);
    }

    public FlipFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public FlipFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mCamera = new Camera();
    }



    @Override
    protected void dispatchDraw(Canvas canvas) {
        mCamera.save();
        canvas.save();
        //镜像反转
        mCamera.rotateY(180);
        Matrix matrix = new Matrix();
        mCamera.getMatrix(matrix);
        matrix.preTranslate(-getWidth()/2,-getHeight()/2);
        matrix.postTranslate(getWidth()/2,getHeight()/2);
        canvas.setMatrix(matrix);
        mCamera.restore();
        super.dispatchDraw(canvas);
        canvas.restore();
    }
}

